package com.rh.number.mapper;

import com.rh.number.builder.FilterSqlBuilder;
import com.rh.number.builder.NumberSqlBuilder;
import com.rh.number.dto.BatchQueryDto;
import com.rh.number.dto.ExcelExportParam;
import com.rh.number.dto.FilterOption;
import com.rh.number.entity.numberEntity;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * (Number)表数据库访问层
 *
 * @author makejava
 * @since 2025-03-22 10:04:00
 */
public interface NumberMapper {
    List<numberEntity> selectByCondition(
            @Param("condition") numberEntity condition,
            @Param("batchQuery") BatchQueryDto batchQuery,  // 调整到第二个参数
            @Param("pageSize") int pageSize,
            @Param("offset") int offset
    );
    List<numberEntity> selectByConditions(@Param("condition") numberEntity condition);
    Long countByCondition(@Param("condition") numberEntity condition);
    Long selectCount(
            @Param("condition") numberEntity condition,
            @Param("batchQuery") BatchQueryDto batchQuery
    );

    @Select("SELECT COUNT(*) FROM number WHERE num = #{num}")
    int countByNum(@Param("num") Long num);
    // 单条插入
    void insert(Number number);

    // 批量插入
    void batchInsert(List<numberEntity> numbers);
    // 根据num批量查询
    List<Long> selectByNum(@Param("nums") List<Long> nums);

    List<numberEntity> batchQueryByNums(@Param("nums") List<String> nums);

    // 批量更新状态
    int batchUpdateStatus(@Param("nums") List<String> nums,
                          @Param("state") String state,
                          @Param("client") String client,
                          @Param("effectiveDate") LocalDate effectiveDate);
    int batchDeactivate(
            @Param("nums") List<String> nums,
            @Param("state") String state,
            @Param("removalTime") LocalDate removalTime
    );

    int batchUpdateByIds(
            @Param("ids") List<Long> ids,
            @Param("fields") Map<String, Object> fields
    );

    int batchUpdateByNums(
            @Param("nums") List<String> nums,
            @Param("fields") Map<String, Object> fields
    );
    // 根据ID查询
    numberEntity selectById(Long id);

    // 根据ID更新
    void updateById(numberEntity entity);

    List<numberEntity> selectForExportByIds(@Param("ids") List<Integer> ids);
    int deleteById(@Param("id") Integer id);
    int deleteBatchIds(@Param("idList") List<Integer> idList);

    void batchFullUpdateByIds(
            @Param("ids") List<Long> ids,
            @Param("entity")  numberEntity entity
    );
    int numinsert(numberEntity entity);

    @Select("SELECT COUNT(*) FROM number WHERE num = #{num}")
    boolean existsByNum(Long num);

    List<numberEntity> exportExcel(@Param("condition") numberEntity condition);
    List<numberEntity> exportByCondition(@Param("condition") ExcelExportParam condition);


    @SelectProvider(type = FilterSqlBuilder.class, method = "buildFilterSql")
    @Results({
            @Result(property = "value", column = "value"),
            @Result(property = "count", column = "count")
    })
    List<FilterOption> getFilterOptions(
            @Param("field") String field,
            @Param("filters") Map<String, String> filters
    );


}

